import { ref } from 'vue';

// 是否显示语言选择器
export const show_language_selector = ref(false);

// 所有语言
export const all_languages = [
    { id: 1, name: 'English', value: 'en', icon: '/language/lang/en.png' },
    { id: 2, name: '繁體', value: 'zh-TW', icon: '/language/lang/tw.png' },
    { id: 3, name: 'हिन्दी', value: 'hi', icon: '/language/lang/hi.png' },
    { id: 4, name: 'Français', value: 'fr', icon: '/language/lang/fr.png' },
    { id: 5, name: 'Español', value: 'es', icon: '/language/lang/es.png' },
    { id: 6, name: 'Deutsch', value: 'de', icon: '/language/lang/de.png' },
    { id: 7, name: 'Italiano', value: 'it', icon: '/language/lang/it.png' },
    { id: 8, name: 'แบบไทย', value: 'th', icon: '/language/lang/th.jpg' },
    { id: 9, name: 'Português', value: 'pt', icon: '/language/lang/pt.png' },
    { id: 10, name: 'Türkçe', value: 'tr', icon: '/language/lang/tr.png' },
    { id: 11, name: '한국인', value: 'ko', icon: '/language/lang/ko.png' },
    { id: 12, name: '日本語', value: 'ja', icon: '/language/lang/ja.png' },
    { id: 13, name: 'Pусский', value: 'ru', icon: '/language/lang/ru.png' },
    { id: 14, name: 'اللغة العربية', value: 'ar', icon: '/language/lang/ar.png' },
    { id: 15, name: 'Tiếng Việt', value: 'vi', icon: '/language/lang/vi.jpg' },
    { id: 16, name: 'Bahasa Indonesia', value: 'id', icon: '/language/lang/id.jpg' },
];

// 当前选择的语言
export const language = ref(all_languages[0]);

// 打开语言选择器
export function openLanguageSelector() {
    show_language_selector.value = true;
}

// 关闭语言选择器
export function closeLanguageSelector() {
    show_language_selector.value = false;
}

// 切换语言
export function changeLanguage(idx) {
    // 判断是否重复选择
    if (all_languages[idx].id != language.value.id) {
        // 切换
        language.value = all_languages[idx];
    }
    // 关闭窗口
    closeLanguageSelector();
}